Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
babel-import-util
Advanced tools
Supply Chain Security
Quality
Maintenance
Vulnerabilities
License
Makes it easier for a babel plugin to emit imported names. Key benefits:
If you want to rewrite:
myTarget('hello world');
To:
import { theMethod } from 'my-implementation';
theMethod('hello world');
Your plugin would look like this:
function testTransform(babel) {
return {
visitor: {
Program: {
enter(path, state) {
// Always instantiate the ImportUtil instance at the Program scope
state.importUtil = new ImportUtil(babel.types, path);
},
},
CallExpression(path, state) {
let callee = path.get('callee');
if (callee.isIdentifier() && callee.node.name === 'myTarget') {
callee.replaceWith(state.importUtil.import(callee, 'my-implementation', 'theMethod'));
}
},
},
};
}
import type { NodePath } from '@babel/traverse';
import type * as t from '@babel/types';
class ImportUtil {
// Import the given value (if needed) and return an Identifier representing
// it.
import(
// the spot at which you will insert the Identifier we return to you
target: NodePath<t.Node>,
// the path to the module you're importing from
moduleSpecifier: string,
// the name you're importing from that module. Use "default" for the default
// export. Use "*" for the namespace.
exportedName: string,
// Optional hint for helping us pick a name for the imported binding
nameHint?: string
): t.Identifier;
// If needed, adds a bare import like:
// import "your-module";
importForSideEffect(moduleSpecifier: string): void;
// Remove an import specifier. If the removed specifier is
// the last one on the whole import statement, the whole
// statement is also removed.
//
// You can use "default" and "*" as exportedName to handle
// those special cases.
removeImport(moduleSpecifier: string, exportedName: string): void;
// Remove all imports from the given moduleSpecifier. Unlike
// removeImport(), this can also remove "bare" import statements
// that were purely for side effect.
removeAllImports(moduleSpecifier: string): void;
}
FAQs
Utility for manipulating imports within babel plugins
The npm package babel-import-util receives a total of 168,286 weekly downloads. As such, babel-import-util popularity was classified as popular.
We found that babel-import-util demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.